/**
 * 用装饰者模式重写第六章中的需求
 * 
 * 礼包码，输入不同的码可以获得游戏币、娃娃、积分、复活币
 * 
 * 抽出一个礼包码的基类，属性有code
 * 细化游戏币、娃娃、积分、复活币的细节
 */
// 第一次代码
/*var Decorator = function(code) {
    this.code = code;
    this.doll = {};
    this.gameCoin = {};
    this.point = {};
    this.resurrectionCoin = {};
}
Decorator.prototype = {
    init: function() {
        var code = this.code;
        getDoll.call(this.doll, code);
        getGameCoin.call(this.gameCoin, code);
        getPoint.call(this.point, code);
        getResurrectionCoin.call(this.resurrectionCoin, code);
    },
    extendObj: function() {}
}

function getDoll(code) {
    var dollCodeMap = {
        10: {name: '1111'}
    };
    for (var k in dollCodeMap[code]) {
        this[k] = dollCodeMap[code][k];
    }
}
function getGameCoin(code) {}
function getPoint(code) {}
function getResurrectionCoin(code) {}

var result = new Decorator(10);
result.init();
console.log(111, result);*/

//第二个代码
var GiftBag = function(code) {
    this.code = code;
    this.giftBag = {
        doll: {}
    };
}

GiftBag.prototype = {
    doll: function() {
        this.giftBag.doll = {};
    },
    gameCoin: function() {
        this.giftBag.gameCoin = {};
    },
    point: function() {
        this.giftBag.point = {};
    },
    resurrectionCoin: function() {
        this.giftBag.resurrectionCoin = {};
    }
};

function getDoll(code) {
    var dollCodeMap = {
        10: {name: '1111'}
    };
    for (var k in dollCodeMap[code]) {
        this[k] = dollCodeMap[code][k];
    }
}
function getGameCoin(code) {}
function getPoint(code) {}
function getResurrectionCoin(code) {}

/**
 * 如何用装饰者模式实现对输入框添加focus与blur事件
 */
var inputDecorator = function(input, eventName, fn) {
    var input = document.getElementById(input);
    if (typeof dom[on + 'eventName'] === 'function') {
        var oldEventFn = dom[on + 'eventName'];

        input['on' + eventName] = function() {
            oldEventFn();
            fn();
        }
    } else {
        input['on' + eventName] = fn();
    }
}
